package com.kaoshi.management.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kaoshi.common.config.Result;
import com.kaoshi.management.pojo.XtManagement;
import com.kaoshi.management.pojo.XtSettingsInformationManagement;
import com.kaoshi.management.service.XtSettingsInformationManagementService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-30
 */
@RestController
@CrossOrigin
@RequestMapping("/settings-information")
public class XtSettingsInformationManagementController {

    @Autowired
    private XtSettingsInformationManagementService SettingsInformationService;

    @PostMapping("/bb/{current}/{limit}")
    public Result findAll(@PathVariable Integer current,
                          @PathVariable Integer limit,
                          @RequestBody XtSettingsInformationManagement xtSettingsInformation) {
        Page<XtSettingsInformationManagement> page = SettingsInformationService.getPage(current, limit,xtSettingsInformation);
        return Result.ok(page);
    }

    @PostMapping("change")
    public Result change(@RequestBody XtSettingsInformationManagement xtSettingsInformation) {
        if(xtSettingsInformation.getId() == null){
            xtSettingsInformation.setPublishstatus(0);
            xtSettingsInformation.setCollectr(0);
            xtSettingsInformation.setIssuer("李明明");
            LocalDate localDate= LocalDate.now();
            xtSettingsInformation.setOperationtime(localDate.atStartOfDay());
            SettingsInformationService.save(xtSettingsInformation);
            return Result.ok("添加成功");
        }else {
            SettingsInformationService.updateById(xtSettingsInformation);
            return Result.ok("修改成功");
        }

    }



    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        SettingsInformationService.removeById(id);
        return Result.ok();
    }

    //    @DeleteMapping("delete/{id}")
//    public Result delete(@PathVariable Integer id) {
//        // 获取要删除的实体
//        XtManagement xtManagement = xtManagementService.getById(id);
//        if (xtManagement != null) {
//            // 设置为逻辑删除状态
//            xtManagement.setLjdelete(1);
//            xtManagementService.updateById(xtManagement); // 更新记录
//        }
//        return Result.ok("删除成功");
//    }



}
